import { msg } from '../notice/notice';

Template.channel_quill.onRendered(function () {
  this.quill = new Quill('#editor', {
    theme: 'snow'
  });
});

Template.channel_quill.events({
  'click #uninstall-app' (e, instance) {
    const options = {
      appId: instance.data.result.appId,
      channelId: instance.data.result.channelId
    };

    $('#channel-quill-modal').modal('hide');

    Meteor.call('uninstallApp', options, (err, res) => {
      if (res) {
        msg({content: '成功删除应用'});
      }
    });
  },
  
  'click #publish-post' (e, instance) {
    const content = instance.quill.root.innerHTML;

    if (content && content != '') {
      const options = {
        channelId: instance.data.result.channelId,
        details: {
          text: content,
          isHTML: true
        }
      };

      Meteor.call('sendChannelMessage', options, (err, res) => {
        if (res) {
          instance.quill.deleteText(0, -1);
          $('#channel-quill-modal').modal('hide');
        }
      });
    }
  }
});